library Claymore initializer init requires LegacySystem


	private function VIDConditions takes nothing returns boolean
		return GetSpellAbilityId()=='A06P'
	endfunction

	private function VID takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer i = GetConvertedPlayerId(p)
		local real x = GetUnitX(u)
		local real y = GetUnitY(u)
		call TriggerSleepAction(0)
		set bj_meleeNearestMineDist = x
		set bj_lastTransmissionDuration = y
		set udg_soundpath = "war3mapImported\\NoAmmo.wav"
		call PlaySoundPath3D.execute()
		call UnitAddAbility(u,'Amin')
		call UnitRemoveAbility(u,'A06P')
		call UnitRemoveAbility(u,'A06O')
		set u = null
	endfunction

	private function IsExplosive takes nothing returns boolean
		return GetUnitTypeId(GetFilterUnit())=='n008'
	endfunction

	private function DetonateConditions takes nothing returns boolean
		return GetSpellAbilityId()=='A06O'
	endfunction

	private function Detonate takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer i = GetConvertedPlayerId(p)
		local integer i2 = 0
		local real x = GetUnitX(u)
		local real y = GetUnitY(u)
		local location l = Location(x,y)
		local group g = AMGetUnitsInRange(250,l,Condition(function IsExplosive))
		local unit explosive
		call DestroyEffect(AddSpecialEffect( "abilities\\weapons\\DemolisherMissile\\DemolisherMissile.mdl",x,y ))
		call TriggerSleepAction(0.)
		loop
			set explosive = FirstOfGroup(g)
			exitwhen explosive==null or i2>1
			call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl",GetUnitX(explosive),GetUnitY(explosive)))
			call GroupRemoveUnit(g,explosive)
			set i2=i2+1
		endloop
		call KillUnit(u)
		if GetWidgetLife(udg_Hero[i])>0.405 then
			call SelectUnitForPlayerSingle(udg_Hero[i],p)
		endif
		call RemoveLocation(l)
		call DestroyGroup(g)
		set g = null
		set l = null
		set u = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
		call TriggerAddCondition( t, Condition( function DetonateConditions ) )
		call TriggerAddAction(t,function Detonate)
		
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
		call TriggerAddCondition( t, Condition(function VIDConditions) )
		call TriggerAddAction(t,function VID)
	endfunction



endlibrary